<?php

/* 
 * 配置
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class configController extends AppController
{
    public function __construct() {
        parent::__construct();
        $this->modelObj = new configModel();
        $this->log_type = '配置管理';
        $this->cookie_key = 'config_cookie';
    }
    
    /**
     * 浏览
     */
    public function view(){
        $this->_get_data();
        $this->display('config_list');
    }
    public function query(){
        $this->_get_data();        
        $this->ret['status'] = 0;
        $this->ret['content'] = $this->fetch('config_list');
        exit(json_encode($this->ret));
    }

    /**
     * 获取数据
     */
    private function _get_data(){
        $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
        $where = '';            
        $filter['txt_code'] = isset($_POST['txt_code']) ? $_POST['txt_code'] : '';
        $filter['txt_value'] = isset($_POST['txt_value']) ? $_POST['txt_value'] : '';
        if($filter['txt_code']) {
            $where .= ' and instr(code, ' . "'{$filter['txt_code']}')";
        }
        if($filter['txt_value']) {
            $where .= ' and instr(value, ' . "'{$filter['txt_code']}')";
        }
        $sort_by = isset($_REQUEST['sort_by']) ? $_REQUEST['sort_by'] : $this->modelObj->keyFields;
        $sort_order = isset($_REQUEST['sort_order']) ? $_REQUEST['sort_order'] : 'DESC';
        $pageObj = new pageModel('config', $where, $this->page_number, 10, $sort_by, $sort_order);        
        $data = $pageObj->pageData($page);    
        $list = $data['pageData'];
        if($list) {
            foreach ($list as $key => $row) {
                $data['pageData'][$key]['sid'] = $key + 1;                
            }
        }
        $this->assign('sort_' . $sort_by, $data['sort_img']);
        $this->assign('data', $data);
    }    
}

